Page({
    data: {
        title: "每日所需卡路里测试",
        brief: '你的身体真的健康吗？赶紧来健康雷达检测一下吧',
        img: 'http://fcdn.qiushilaile.com/game/default-2111621235012128.png',
        healthNum: 111,
        desc: '你的身体真的健康吗？赶紧来健康雷达检测一下吧',
        goodsId: 'leida',
        timu: [{
            question: "您的性别是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-29991611050055611.jpg",
            options: [{
                leap: "A",
                option: "男生",
                fs: 0,
            }, {
                leap: "B",
                option: "女生",
                fs: 0,
            }, ]
        }, {
            question: "您的年龄是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-14601611050074691.jpg",
            options: [{
                option: 0,
                fs: 0,
            }]
        }, {
            question: "您的身高是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-14601611050074691.jpg",
            options: [{
                option1: 0,
                fs: 0,
            }]
        }, {
            question: "您的体重是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-14601611050074691.jpg",
            options: [{
                option2: 0,
                fs: 0,
            }]
        }, ],
        array: ['10',
            '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
            '21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
            '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
            '41', '42', '43', '44', '45', '46', '47', '48', '49', '50',
            '51', '52', '53', '54', '55', '56', '57', '58', '59', '60',
        ], // 年纪
        arrayO: ['140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150',
            '151', '152', '153', '154', '155', '156', '157', '158', '159', '160',
            '161', '162', '163', '164', '165', '166', '167', '168', '169', '170',
            '171', '172', '173', '174', '175', '176', '177', '178', '179', '180',
            '181', '182', '183', '184', '185', '186', '187', '188', '189', '190',
            '191', '192', '193', '199', '195', '196', '197', '198', '199', '200'
        ], // 身高
        array1: [
            '40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
            '50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
            '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
            '70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
            '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
            '90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
            '100', '101', '102', '103', '104', '105', '106', '107', '108', '109',
            '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120'
        ], // 体重
        progress: 0,
        choiceArray: [],
        commentList: [{
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-86481625544662634.png',
            comment: '测试结果这么准的吗'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-32181625544694629.png',
            comment: '没想到啊没想到'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-16911625544715042.png',
            comment: '啦啦啦啦啦啦啦'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-86481625544662634.png',
            comment: '建议重生 呜呜呜呜'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-32181625544694629.png',
            comment: ' 原来我的数值这么高'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-16911625544715042.png',
            comment: '哈哈哈哈哈哈我的还不错'
        }, ],
    },
    onLoad: function(options) {
        // console.log(this.data.title);
        // console.log(this.data.timu);
    },
    bindPickerChange(e) { // 身高picker选择器
        this.animate();
        console.log('picker发送选择改变，携带值为', e.detail.value);
        this.setData({
            index: e.detail.value,
            height: this.data.array[e.detail.value],
        })
        console.log('身高', this.data.array[e.detail.value]);
        if (this.data.toolNum == '5') {
            this.setData({
                layerPopup: true
            });
            return
        }
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
    },
    bindPickerChange1(e) { // 体重picker选择器
        console.log('picker发送选择改变，携带值为', e.detail.value);
        this.animate();
        this.setData({
            indexO: e.detail.value,
            weight: this.data.arrayO[e.detail.value],
        })
        console.log('体重', this.data.arrayO[e.detail.value]);
        // setTimeout(() => {
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
        // }, 1000);
        // if (this.data.progress == '3') {
        //     console.log('跳出弹窗观看视频进行跳转', '性别', this.data.sex, '身高', this.data.height, '体重', this.data.weight);
        //     this.setData({
        //         layerPopup: true
        //     })
        // }
    },
    bindPickerChange2(e) { // 体重picker选择器weight1
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index1: e.detail.value,
            weight1: this.data.array1[e.detail.value],
        })
        console.log('体重', this.data.array1[e.detail.value]);
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
        console.log(this.data.progress);
        if (this.data.progress == '4') {
            console.log('性别', this.data.sex, '年纪', this.data.height, '身高', this.data.weight, '体重', this.data.weight1);
            this.setData({
                layerPopup: true
            })
        }
    },
    animate() {
        const animation = tt.createAnimation({
            duration: 500,
        });
        this.animation = animation;
        this.animation.opacity(0).translateX('400px').step({
            duration: 50,
        }).opacity(1).translateX('0px').step({
            duration: 1000,
        })
        this.setData({
            animationData: this.animation.export(),
        });
    },
    toResult() {
        if (this.data.sex == '男生') {
            console.log('man');
            let dcr = (66 + (13.7 * this.data.weight1) + (5 * this.data.weight) - (6.8 * this.data.height)).toFixed(1)
            console.log('每日所需kacl为', dcr);
            this.setData({
                dcr
            })
            tt.navigateTo({
                url: '/pages/result/result?tools=dcr&dcr=' + this.data.dcr // 指定页面的url
            });

        }
        if (this.data.sex == '女生') {
            console.log('woman');
            let dcr = 655 + (9.6 * this.data.weight1) + (1.7 * this.data.weight) - (4.7 * this.data.height)
            console.log('每日所需kacl为', dcr);
            this.setData({
                dcr
            })
            tt.navigateTo({
                url: '/pages/result/result?tools=dcr&dcr=' + this.data.dcr // 指定页面的url
            });
        }
    },
    itemClick(e) {
        // var index1 = e.currentTarget.dataset.fs
        // var indexArr = this.data.choiceArray
        // indexArr.push(index1)

        // this.setData({
        //     id: index1,
        //     choiceArray: indexArr // choiceArray用来存放选择的选项
        // })
        // console.log(this.data.choiceArray);

        // if ((this.data.progress + 1) == this.data.timu.length) { // 答完题跳转
        //   let sum = 0;
        //   let arr = this.data.choiceArray
        //   arr.forEach(item => {
        //     sum = sum + item
        //   })
        //   console.log(sum, 'sum跳转');
        //   this.setData({
        //     lookResultLayer: true,
        //   })
        //   return
        // }
        // setTimeout(() => {
        // if (this.data.progress == '0') {
        //     this.setData({
        //         id: null,
        //         progress: this.data.progress + 1
        //     });
        // }
        // }, 1000)
        this.setData({
            id: e.currentTarget.dataset.index,
            active: true,
        })
        console.log(e.currentTarget.dataset.index);
        if (this.data.progress == '0') {
            setTimeout(() => {
                this.animate();
                this.setData({
                    id: null,
                    sex: e.currentTarget.dataset.value,
                    progress: this.data.progress + 1
                });
                console.log(this.data.active);
            }, 500);

        }
    },
    closeClick() {
        // setTimeout(() => {
        this.setData({
            layerPopup: false,
        });
        wx.navigateBack({
                delta: 1
            })
            // }, 50);
    },
})